package shutdown;

import java.util.*;
import java.net.*;
import net.hangar5.xmlrpc.*;

public class ShutDown
{
  URL url;
  RpcClient myClient;

  public ShutDown()
  {
     this.url = url;
     try
     {
	myClient = new RpcClient();
     }
     catch (Exception other)
     {
	 System.err.println ("Exception in client: "+ other);
	 other.printStackTrace();
     }
     myClient.setKeepAlive(false);
  }

  public boolean setURL(String url)
  {
      boolean result = false;
      try
      {
	  myClient.setUrl(url);
	  result = true;
      }
      catch(Exception e){}
      return result;
  }

  public boolean shutDownApp(int type)
  {
      boolean result = false;
      String methode = "";
      switch(type)
      {
	  case 0:
	      methode = "shutDown";
	      break;
	  case 1:
	      methode = "shutDownAffichage";
	     break;
      }
      try
      {
	  Vector v = new Vector();
	  Object o = myClient.execute (methode, v);
	  if (o != null) result = true; ;
      }
      catch (Exception x) {printErreur(x, methode);}
      return result;
  }


  private final void printErreur(final Exception x, final String methode)
  {
      System.out.println("Execution de la méthode: " + methode + " impossible sur la borne dont l'url est: " + url + "  [" + x.toString() + "]");
  }


}